<template>
	<view class="container">
		<view class="fitem">
			<view class="title">昵称</view>
			<view class="input"><uni-easyinput v-model="nickname" placeholder="请输入昵称" ></uni-easyinput></view>
		</view>
 
		<view class="f-footer">
		   <text class="sbtn" @click="saveuserinfo">保存</text>	
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickname:"",
			}
		},
		onLoad(option) {
			this.getUserinfo();
		},
		methods: {
			getUserinfo(){
				let that = this;
				this.$util.req("/user/getInfo",{},true,function(res){
 
							that.nickname = res.data.nickname;
			 
				});
			},
			 saveuserinfo(){
				let params={
					"upfield":"nickname",
					"fieldvalue":this.nickname,
 				}
				let that = this;
				this.$util.req("/user/updateinfo",params,true,function(res){
				 
				uni.$emit("changenickname",that.nickname);
				uni.navigateBack();
				});
			 },
			sendsms(){
				console.log("dddd");
				if(!this.mobile){
					uni.showToast({
						title:"请输入手机号"
					});
					return ;
				}
				if(!this.smsbtn_status){
					return ;
				}
				console.log("下发短信");
				let that = this;
				//请求接口
				this.$util.req("/user/sendsms",{"smstype":"login","mobile":this.mobile},true,function(res){
			  	   console.log("下发成功");
				   that.smsbtn_status = false;
				   let maxsec=60;//60秒
					//倒计时
					let timeoutID = setInterval(function(){
						
						maxsec = maxsec-1;
						that.smsbtn=maxsec+"秒";
						
						if(maxsec==0){
							console.log("清楚定时器");
							that.smsbtn_status=true;
							that.smsbtn="获取验证码";
							clearInterval(timeoutID);
						}
					},1000);
					
				});
			}
		}
	}
</script>

<style lang="scss">
 .container{
	 display: flex;
	 flex-direction: column;
	padding: 20upx;
 }
 .f-footer{
	 margin-top: 30upx;
	 display: flex;
	 justify-content: center;
	 align-items: center;
	 .sbtn{
		 
		 background-color: #FA436A;
		 color: #FFFFFF;
		 border-radius: 10upx;
		 padding: 10upx 60upx;
	 }
 }
 .fitem{
	 padding-bottom: 20upx;
 	display: flex;
	align-items:baseline;
	.title{
		flex:1

	}
	.sendbtn{
		margin-left: 10upx;
		color: $font-color-base;
		border: 1px solid $border-color-base;
		padding: 10upx 20upx;
	}
	.input{
		display: flex;
		align-items: baseline;
		flex:5;
		margin-left: 10upx;
	} 
 }
</style>
